using System;
using System.Collections.Generic;
using System.Reflection;
using Castle.Core;
using Castle.MonoRail.Framework;
using Castle.MonoRail.WindsorExtension;

namespace AspView.com
{
	public class IoCContainer : Castle.Windsor.WindsorContainer
	{
		public void Initialize()
		{
			AddFacility("rails", new RailsFacility());
			#region web

			// registering all controllers in current assembly
			List<Type> controllers = (new List<Type>(Assembly.GetExecutingAssembly().GetTypes()))
				.FindAll(delegate(Type type)
				         	{
				         		return type.IsSubclassOf(typeof (Controller));
				         	});
			foreach (Type controllerType in controllers)
				AddComponentWithLifestyle(controllerType.FullName, controllerType, LifestyleType.Transient);

			AddComponentWithLifestyle<Components.Menu>("MenuComponent", LifestyleType.Transient);

			#endregion
		}
	}
}
